home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / v cisle / steadystate / SteadyState_Setup_ENU.exe / windowsupdates.vbs < prev   
Encoding:
Text (UTF-16)  |  2007-05-10  |  12.7 KB  |  148 lines

  1. ' ***
  2. ' *** ------------------------------------------------------------------------------
  3. ' *** Filename:        WindowsUpdates.vbs
  4. ' *** ------------------------------------------------------------------------------
  5. ' *** Description:    Automatically downloads and installs relevant updates
  6. ' *** ------------------------------------------------------------------------------
  7. ' *** Version:        1.0
  8. ' *** Notes:        
  9. ' *** ------------------------------------------------------------------------------
  10. ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
  11. ' *** ------------------------------------------------------------------------------
  12. ' *** 
  13.  
  14. ' ~~~ 
  15. ' ~~~ Force variables to be declared 
  16. ' ~~~ 
  17. Option Explicit
  18.  
  19. Dim I, I2, oSession, oSearcher, oSearchResult, oUpdate, oUpdatesToDownload, oUpdatesToInstall, oDownloader, oInstaller, oInstallationResult
  20. Dim oFileSystem, oLog
  21. dim oWinFolder
  22.  
  23.  
  24.  
  25. ' ~~~ ------------------------------------------------------------------------------
  26. ' ~~~ Create objects
  27. ' ~~~ ------------------------------------------------------------------------------
  28. Set oSession       = CreateObject("Microsoft.Update.Session")
  29. Set oSearcher      = oSession.CreateupdateSearcher()
  30.  
  31. Set oFileSystem = CreateObject("Scripting.FileSystemObject")
  32. Set oWinFolder = oFileSystem.GetSpecialFolder (0)
  33. Set oLog = oWinFolder.CreateTextFile("SCTWindowsUpdates.log", True)
  34.  
  35. Public Function DoWindowsUpdates
  36.  
  37. On Error Resume Next
  38.  
  39.     ' ~~~ ------------------------------------------------------------------------------
  40.     ' ~~~ Search for updates
  41.     ' ~~~ ------------------------------------------------------------------------------
  42.     oLog.WriteLine FormatDateTime (Now) & " Searching for updates..." & vbCRLF
  43.     oLog.WriteLine FormatDateTime (Now) & " List of applicable items on the machine:"
  44.     
  45.     I2=0
  46.     For I = 0 To oSearchResult.Updates.Count-1
  47.         Set oUpdate = oSearchResult.Updates.Item(I)
  48.         I2=I2+1
  49.         oLog.WriteLine I + 1 & "> " & oUpdate.Title
  50.     Next
  51.     
  52.     If I2 = 0 Then
  53.         oLog.WriteLine FormatDateTime (Now) & " There are no applicable updates."
  54.         Exit Function        
  55.     End If
  56.     
  57.     ' ~~~ ------------------------------------------------------------------------------
  58.     ' ~~~ Create collection of upates to download
  59.     ' ~~~ ------------------------------------------------------------------------------
  60.     oLog.WriteLine vbCRLF & FormatDateTime (Now) & " Creating collection of updates to download:"
  61.     Set oUpdatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
  62.     
  63.     For I = 0 to oSearchResult.Updates.Count-1
  64.         Set oUpdate = oSearchResult.Updates.Item(I)
  65.         oLog.WriteLine I + 1 & "> adding: " & oUpdate.Title 
  66.         oUpdatesToDownload.Add(oUpdate)
  67.     Next
  68.     
  69.     ' ~~~ ------------------------------------------------------------------------------
  70.     ' ~~~ Download updates
  71.     ' ~~~ ------------------------------------------------------------------------------
  72.     oLog.WriteLine vbCRLF & FormatDateTime (Now) & " Downloading updates..."
  73.     
  74.     Set oDownloader = oSession.CreateUpdateDownloader() 
  75.     oDownloader.Updates = oUpdatesToDownload
  76.     oDownloader.Download()
  77.     
  78.     ' ~~~ ------------------------------------------------------------------------------
  79.     ' ~~~ Create a collection of downloaded updates to install
  80.     ' ~~~ ------------------------------------------------------------------------------
  81.     oLog.WriteLine  vbCRLF & FormatDateTime (Now) & " Creating collection of downloaded updates to install:" 
  82.     Set oUpdatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
  83.     
  84.     For I = 0 To oSearchResult.Updates.Count-1
  85.         Set oUpdate = oSearchResult.Updates.Item(I)
  86.         oLog.WriteLine I + 1 & "> adding:  " & oUpdate.Title 
  87.         oUpdatesToInstall.Add(oUpdate)    
  88.     Next
  89.     
  90.     ' ~~~ ------------------------------------------------------------------------------
  91.     ' ~~~ Install updates
  92.     ' ~~~ ------------------------------------------------------------------------------
  93.     oLog.WriteLine FormatDateTime (Now) & " Installing updates..."
  94.     Set oInstaller = oSession.CreateUpdateInstaller()
  95.     oInstaller.Updates = oUpdatesToInstall
  96.     oInstaller.ForceQuiet = true
  97.     Set oInstallationResult = oInstaller.Install()
  98.     
  99.     ' ~~~ ------------------------------------------------------------------------------
  100.     ' ~~~ Output results of install
  101.     ' ~~~ ------------------------------------------------------------------------------
  102.     oLog.WriteLine FormatDateTime (Now) & " Installation Result: " & oInstallationResult.ResultCode 
  103.     oLog.WriteLine FormatDateTime (Now) & " Reboot Required: " & oInstallationResult.RebootRequired & vbCRLF 
  104.     oLog.WriteLine FormatDateTime (Now) & " Listing of updates installed and individual installation results:" 
  105.     
  106.     For I = 0 to oUpdatesToInstall.Count - 1
  107.         oLog.WriteLine I + 1 & "> " & oUpdatesToInstall.Item(i).Title & ": " & oInstallationResult.GetUpdateResult(i).ResultCode
  108.     Next
  109.     
  110. End Function
  111.  
  112.  
  113.  
  114. On Error Resume Next
  115.  
  116. oLog.WriteLine FormatDateTime (Now) & " Downloading and Installing Update Rollups"
  117. Set oSearchResult  = oSearcher.Search("IsInstalled=0 and Type='Software' and CategoryIDs contains '28BC880E-0592-4CBF-8F95-C79B17911D5F'")
  118. Call DoWindowsUpdates
  119. oLog.WriteLine vbCRLF & vbCRLF
  120.  
  121.  
  122. oLog.WriteLine FormatDateTime (Now) & " Downloading and Installing Security Updates"
  123. Set oSearchResult  = oSearcher.Search("IsInstalled=0 and Type='Software' and CategoryIDs contains '0FA1201D-4330-4FA8-8AE9-B877473B6441'")
  124. Call DoWindowsUpdates
  125. oLog.WriteLine vbCRLF & vbCRLF
  126.  
  127.  
  128. oLog.WriteLine FormatDateTime (Now) & " Downloading and Installing Service Packs"
  129. Set oSearchResult  = oSearcher.Search("IsInstalled=0 and Type='Software' and CategoryIDs contains '68C5B0A3-D1A6-4553-AE49-01D3A7827828'")
  130. Call DoWindowsUpdates
  131. oLog.WriteLine vbCRLF & vbCRLF
  132.  
  133.  
  134. ' Definition Updates, for Windows Defender
  135. oLog.WriteLine FormatDateTime (Now) & " Downloading and Installing Definition Updates"
  136. Set oSearchResult  = oSearcher.Search("IsInstalled=0 and Type='Software' and CategoryIDs contains 'e0789628-ce08-4437-be74-2495b842f43b'")
  137. Call DoWindowsUpdates
  138. oLog.WriteLine vbCRLF & vbCRLF
  139.  
  140. oLog.WriteLine FormatDateTime (Now) & " Downloading and Installing Critical Updates"
  141. Set oSearchResult  = oSearcher.Search("IsInstalled=0 and Type='Software' and CategoryIDs contains 'e6cf1350-c01b-414d-a61f-263d14d133b4'")
  142. Call DoWindowsUpdates
  143. oLog.WriteLine vbCRLF & vbCRLF
  144.  
  145. oLog.WriteLine FormatDateTime (Now) & " Updates Complete"
  146.  
  147. oLog.Close
  148.